import { getToken, removeToken, setToken } from '@/utils/auth'
import { login,loginsupplier } from '@/api/login'

export default {
  namespaced: true,
  state: {
    token: getToken() || '',
    userInfo: {}
  },
  mutations: {
    updateToken(state, token) {
      state.token = token

      // 存储到本地 Cookie
      setToken(token)
    },
    updateUserInfo(state, userInfo) {
      state.userInfo = userInfo
    },
    removeToken(state) {
      state.token = ''
      removeToken()
    },
    removeUserInfo(state) {
      state.userInfo = {}
    }
  },
  actions: {
    async userLogin(context, loginForm) {
      const res = await login(loginForm)
      const com = await loginsupplier(loginForm)
      // console.log('登录成功的结果:', res)
      // 调用 mutations 的 updateToken 存储即可
      context.commit('updateToken', res.data)
      context.commit('updateToken', com.data)
      return res, com
    },

  },
  getters: {}
}
